
@extends('layouts.default')

@section('title', '')

@push('scripts')
<script>
    layui.use(['layer', 'element','form','table','laypage','laytpl','laydate'], function(){
        var layer = layui.layer;
        var form = layui.form;
        var element = layui.element;
        var table = layui.table;
        var laypage = layui.laypage;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var param = {}; 
        var checkboxdata = '';
        var materials_date = "{{request()->get('materials_date',0)}}";
        var key = "{{request()->get('key','')}}";
    
        getList(1);
        renderSelect();

        //日期时间范围
        laydate.render({
            elem: '#test10'
            ,type: 'date'
            ,range: true
        });
      
        //下拉框初始化
        function renderSelect(){
              
        }

        // 查询
        form.on('submit(queryBtn)', function(data) {
            Object.assign(param, {
                    "search": data.field
            });
            getList(1);
            return false; 
        });
       
        //重置
        $('button[type=reset]').click(function(){
            $('#search-form')[0].reset();
            $('button[lay-filter=queryBtn]').click(); 
            return false;    
        })

        function getList(page){
            Object.assign(param,{"page":page});	           
            let whereStr = ''; 
            if(key.length > 0){
                switch (key) { 
                    case "0": 
                        whereStr = " (JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 145)) or JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 146)) or JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 147))) and ( JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 106)) or JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 151)) ) ";
                    break; 
                    case "1": 
                        whereStr = " (JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 145)) or JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 146)) or JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 147))) and  ( JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 107)) or JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 191)) )";
                    break; 
                    case "2": 
                        whereStr = " (JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 145)) or JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 146)) or JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 147))) and  ( JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 192)) or JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 108)) )";
                    break; 
                    case "3": 
                        whereStr = " (JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 236)) or JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 148)) or JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 150))) and  ( JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 192)) or JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 108)) or JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 107)) or JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 191)) )";
                    break; 
                    case "4": 
                        whereStr = " (JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 145)) or JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 146)) or JSON_CONTAINS(`activity_info`.category,JSON_OBJECT('optionId', 147))) and ( JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 111)) or JSON_CONTAINS(`activity_info`.level,JSON_OBJECT('optionId', 196)) ) ";
                    break;     
                }
            } 
            Object.assign(param, {"search": {'status':'PASS','materials_date': materials_date,whereStr:whereStr}}); 
            getAwardsList(param,function(res){		
                if(res.code == 1){
                    table.render({
                        elem: '#tablelist'
                        ,toolbar: '#toolbarDemo'
                        ,defaultToolbar:[]
                        ,data: res.data.data
                        ,limit:res.data.limit
                        ,id:'idTest'
                        ,skin:'nob'
                        ,even:true
                        //,cellMinWidth: 80 //全局定义常规单元格的最小宽度，layui 2.2.1 新增
                        ,cols: [[ 
                        {type: 'checkbox', fixed: 'left'},
                        {field: '', title: '学年学期',width:'10%',align:'center',templet: function(d) {
                            // return (page-1)*res.data.limit+d.LAY_INDEX;
                            if(d.data_version_name === null){
                                return '';
                            }else{
                                return d.data_version_name;
                            }                        
                        }}
                        ,{field: '', title: '类型',width:'10%',align:'center',templet: function(d) {
                            if(d.category_array.length>0){
                                return d.category_array[0].selectValue;
                            }else{
                                return '';
                            }                       
                       }}								                  							
                        ,{field: 'name', title: '名称',width:'10%',align:'center'}								                  
                        ,{field: 'begin_date', title: '开始日期',width:'10%',align:'center'}																
                        ,{field: 'end_date', title: '结束日期',width:'10%',align:'center'}																
                        ,{field: '', title: '级别',width:'5%',align:'center',templet: function(d) {
                            if(d.level_array.length>0){
                                return d.level_array[0].selectValue;
                            }else{
                                return '';
                            } 
                       }}																
                       ,{field: '', title: '等级',width:'5%',align:'center',templet: function(d) {
                            if(d.grade_array.length>0){
                                return d.grade_array[0].selectValue;
                            }else{
                                return '';
                            } 
                       }}	
                       ,{field: '', title: '状态',width:'10%',align:'center',templet: function(d) {
                            if(d.status == 'FILL_IN'){
                                return '未提交';
                            }else if(d.status == 'REVIEW'){
                                return '待审核';
                            }else if(d.status == 'REVIEW_FAIL'){
                                return '已驳回';
                            }else if(d.status == 'PASS'){
                                return '审核通过';
                            }else{
                                return '-';
                            }
                           
                       }}																
                       ,{field: 'nickname', title: '创建人',width:'10%',align:'center'}														
                        ,{field: '', title: '操作',toolbar: '#barDemo',width:'',align:'center'}
                        ]]
                    });

                    $('#pageBar').empty();                     
                    if(res.data.total >0){
                        //分页
                        laypage.render({
                        elem: 'pageBar' //注意，这里的 test1 是 ID，不用加 # 号
                        ,count: [res.data.total] //数据总数，从服务端得到
                        ,curr: page
                        ,layout: ['limit', 'count', 'prev', 'page', 'next',  'skip']                               
                        ,limit:res.data.limit
                        ,jump: function(obj, first) {
                                //首次不执行
                                if (!first) {
                                    Object.assign(param,{"limit":obj.limit});                                
                                    getList(obj.curr)
                                }
                            }
                        });
                    } 
                     setBtnPermission();                           
                }else {
                    layer.msg(res.msg, {icon: 5});
                } 
                                    
            })
        }



        table.on('tool(tablelist)', function(obj){ //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
     
            if(layEvent === 'del'){ //删除
                layer.confirm('确定删除吗?', function(index){
                    delAwards({'id':data.id},function(res){
                        if(res.code == '1'){
                            layer.msg(res.msg,{icon: 6,time: 1000});
                            obj.del(); 
                            layer.close(index);
                        }else{
                            layer.msg(res.msg, {icon: 5,shift : 6});
                        }
                    })
                
                
                });
            }else if(layEvent === 'edit'){     
              window.location.href = "{{route('awards.wards.add')}}?id="+data.id;
     
            }else if(layEvent === 'check'){
                window.location.href = "{{route('awards.wards.check')}}?id="+data.id;
               
            }else if(layEvent === 'see'){
                window.location.href = "{{route('awards.wards.see')}}?id="+data.id;
            }
        });


        $('#click-checkbox').click(function(){
            var checkStatus = table.checkStatus('idTest');
            window.parent.checkboxdata = checkStatus;     
        })
              
    })
</script>


<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="see"  btnPermission="179">查看</a>
</script>
<!---头部工具栏--->
<script type="text/html" id="toolbarDemo">
   
    <div class="list-head">
            <h3>获奖情况列表</h3>
            <div class="layui-btn-container list-opt-btns">
                <a btnPermission="176" class="layui-btn layui-btn-normal" href="{{route('awards.wards.add')}}" id="addBtn"> + 新增 </a>
            </div>
        </div>
</script>

@endpush

@section('content')
    <style>
         /* .layui-table-body{
            overflow: hidden;
        }  */
    </style>

    <div class="layui-card">

        <div class="layui-card-body">
            <table class="layui-table" id="tablelist" lay-filter="tablelist"></table>
            <div class="pagebarbox" style="text-align: end"><div id="pageBar" class="pagebar"></div></div>
        </div>
    </div>
  
   <button style="display:none" id="click-checkbox" ></button>
@endsection
